package net.lab1024.smartadmin.module.business.vehicleConfiguration.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.domain.dto.VehicleConfigurationAddDTO;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.domain.dto.VehicleConfigurationQueryDTO;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.domain.dto.VehicleConfigurationUpdateDTO;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.domain.vo.VehicleConfigurationExcelVO;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.domain.vo.VehicleConfigurationVO;
import net.lab1024.smartadmin.module.business.vehicleConfiguration.service.VehicleConfigurationService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ �������� ]
 *
 * @author �Ζ�
 * @version 1.0
 * @company ��������
 * @copyright (c)  ��������Inc. All rights reserved.
 * @date 2021-11-19 11:20:38
 * @since JDK1.8
 */
@RestController
@Api(tags = {"��������"})
public class VehicleConfigurationController extends BaseController {

    @Autowired
    private VehicleConfigurationService vehicleConfigurationService;

    @ApiOperation(value = "��ҳ��ѯ��������",notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/page/query")
    public ResponseDTO<PageResultDTO<VehicleConfigurationVO>> queryByPage(@RequestBody VehicleConfigurationQueryDTO queryDTO) {
        return vehicleConfigurationService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "�����������",notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/add")
    public ResponseDTO<String> add(@RequestBody @Validated VehicleConfigurationAddDTO addTO){
        return vehicleConfigurationService.add(addTO);
    }

    @ApiOperation(value="�޸���������",notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/update")
    public ResponseDTO<String> update(@RequestBody @Validated VehicleConfigurationUpdateDTO updateDTO){
        return vehicleConfigurationService.update(updateDTO);
    }

    @ApiOperation(value="����ɾ����������",notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return vehicleConfigurationService.deleteByIds(idList);
    }

    @ApiOperation(value = "��������", notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //��ѯ����
        List<VehicleConfigurationExcelVO> vehicleConfigurationList = vehicleConfigurationService.queryBatchExportData(idList);
        //��������
        ExportParams ex = new ExportParams("��������", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, VehicleConfigurationExcelVO.class, vehicleConfigurationList);
        downloadExcel("��������", workbook, response);
    }

    @ApiOperation(value = "����ȫ��", notes = "@author �Ζ�")
    @PostMapping("/vehicleConfiguration/export/all")
    public void exportAll(@RequestBody @Validated VehicleConfigurationQueryDTO queryDTO, HttpServletResponse response) {
        //��ѯ����
        List<VehicleConfigurationExcelVO> vehicleConfigurationList = vehicleConfigurationService.queryAllExportData(queryDTO);
        //��������
        ExportParams ex = new ExportParams("��������", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, VehicleConfigurationExcelVO.class, vehicleConfigurationList);
        downloadExcel("��������", workbook, response);
    }

}
